package com.zhiyou.servlet.house;

import java.io.IOException;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhiyou.service.HouseService;
import com.zhiyou.serviceImpl.HouseServiceImpl;

/**
 * Servlet implementation class HouseUpdateServlet
 */
@WebServlet("/HouseUpdateServlet")
public class HouseUpdateServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public HouseUpdateServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		HouseService hs = new HouseServiceImpl();
		String area = request.getParameter("h_area");
		String estate = request.getParameter("h_estate");
		String num = request.getParameter("h_unitNumber");
		int floor = Integer.parseInt(request.getParameter("h_floor"));
		String room = request.getParameter("h_roomNo");
		String acreage = request.getParameter("h_acreage");
		String fit = request.getParameter("h_fitment");
		String direction = request.getParameter("h_direction");
		int isd = Integer.parseInt(request.getParameter("h_isDoubleAir"));
		int limit = Integer.parseInt(request.getParameter("h_limit"));
		String facility = request.getParameter("h_facility");
		double price = Double.parseDouble(request.getParameter("h_price"));
		int status = Integer.parseInt(request.getParameter("h_status"));
		String img = request.getParameter("h_img");
		String address = request.getParameter("h_address");
		int id = Integer.parseInt(request.getParameter("h_id"));
		Object obj[] = {area,estate,num,floor,room,acreage,fit,
				direction,isd,limit,facility,price,status,img,address,id};
		boolean flag = hs.update(obj);
		if(flag){
			request.setAttribute("msg", "修改成功");
			request.getRequestDispatcher("/HouseShowServlet?1=1").forward(request, response);
		}else{
			request.setAttribute("msg", "修改失败");
			request.getRequestDispatcher("/HousefindServlet?h_id="+id).forward(request, response);
		}
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
